<?php
/**
* Django's templating engine (partial) PHP implementation.
* provides some template tags support
* @link http://djangoproject.com
* this file is from a webappkit package (kit)
* @link http://webappkit.net
* @package djtpl
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* ifequal tag node.
* <code>{% ifequal operand1 operand2 %}{% endifequal %}</code>
*/
class djtplTagNode_ifEqual extends djtplTagNode {
    /**
    * builds itself from tokens
    * @param djangoTplToken &$selfToken
    * @param array &$nextTokens djangoTplToken
    * @access public
    * @return bool
    */
    function buildFromTokens(&$selfToken,&$nextTokens) {
        // parsing def
        $operandRegex='([^" ]+)|("[^"]*")';
        //$this->operands=explode(' ',$selfToken->getTagDef());
        if (ereg('^('.$operandRegex.') ('.$operandRegex.')$',$selfToken->getTagDef(),$search)) {
            // operands are at index 1 and 5
            //echo wakdebug::vardump($search);
            $this->operand1=$search[1];
            $this->operand2=$search[4];
        }
        
        $this->buildChildNodesFromTokens($nextTokens);
        return true;
    }/**/

    /**
    * is the node atomic (has no children)
    * @access public
    * @return bool
    */
    function isAtomic() {
        return false;
    }/**/
    
    /**
    * renders with some data
    * @param djangoTplContext &$context
    * @access public
    * @return string
    */
    function render(&$context) {
        $value1=djtplParser::evalexpression($context,$this->operand1);
        $value2=djtplParser::evalexpression($context,$this->operand2);
        //echo wakdebug::vardump($value1).'='.wakdebug::vardump($value2).' ?';
        //echo $this->operand1.wakaffvar($value1).'?='.$this->operand2.wakaffvar($value2);
        if ($value1==$value2) {
            //echo wakdebug::vardump($value1).'='.wakdebug::vardump($value2);
            return $this->renderChildNodesBeforeTag($context,'else');
        } else
            return $this->renderChildNodesAfterTag($context,'else');
    }/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
    /**
    * @var string
    */
    var $tagname='ifequal';
    /**
    * @var mixed
    */
    var $operand1;
    var $operand2;
}/**/
?>
